#include <future>
#include <gtest/gtest.h>
#include <iostream>

#include "log/logger.h"
#include "sync/os_semaphore.h"
#include "thread/os_thread.h"
// 测试os_thread的detach接口功能
TEST(OsThreadTest, DetachThread)
{
    os_thread thread;
    os_semaphore sem(0);
    thread.create(
        [&sem]() {
            os_thread::sleep_ms(1000);
            sem.signal();
        },
        os_thread::FUNCTION_SHORT_TASK, 0);
    thread.set_thread_name("DetachThread");
    thread.start();
    // 分离线程
    bool ret = thread.detach();
    EXPECT_TRUE(ret);
    LOGI("wait thread");
    sem.wait();
    LOGI("wait thread end");
}